﻿using System.Collections.Generic;

namespace MathService
{
    public class LimitedQueue<T> : Queue<T>
    {
        private int f_Capacity;

        public int Capacity { get { return f_Capacity; } set { f_Capacity = value; Check(); } }

        public LimitedQueue(int Capacity) { this.Capacity = Capacity; }

        public new void Enqueue(T item)
        {
            base.Enqueue(item);
            Check();
        }

        private void Check() { while(Count > f_Capacity) Dequeue(); }
    }
}
